<?php
	
	include '../lib/config.inc.php';
	$codig = $_GET['codig'];
	
	$sql = "SELECT * FROM movimentacoes WHERE movimentacoes.caixa_id = $codig ORDER BY data DESC";

	$result = mysql_query($sql);
	$igreja = mysql_fetch_array(mysql_query("SELECT igreja FROM caixas, igrejas WHERE caixas.igreja_id = igrejas.id AND caixas.id = $codig"));
	require("../fpdf/fpdf.php");
	
	$pdf= new FPDF("P","pt","A4");
	
	$pdf->AddPage();
	$pdf->SetFont('Times','B',14);
	$pdf->Cell(0,20,utf8_decode("Relatório de Entradas e Saídas da igreja {$igreja['igreja']}"),0,1,'C');
	$pdf->Cell(528,5,"","B",1,'C');
	$pdf->Ln(20);
	
	$n = 0;
	$pdf->SetFont('Times','b',10);
	$pdf->Cell(18,20,utf8_decode('id'),1,0,"C");
	$pdf->Cell(140,20,utf8_decode('Movimentação'),1,0,"L");
	$pdf->Cell(60,20,utf8_decode('Data'),1,0,"L");
	$pdf->Cell(50,20,utf8_decode('Valor'),1,0,"L");
	$pdf->Cell(100,20,utf8_decode('Origem/Destino'),1,0,"L");
	$pdf->Cell(40,20,utf8_decode('Tipo'),1,0,"L");
	$pdf->Cell(120,20,utf8_decode('Igreja'),1,0,"L");
	$pdf->Ln();
	$pdf->SetFont('Times','',10);
	while ($row = mysql_fetch_array($result)){
		$pdf->Cell(18,20,utf8_decode($row['id']),1,0,"C");		
		$pdf->Cell(140,20,utf8_decode($row['movimentacao']),1,0,"L");
		$data = $row['data'];
		$data = implode("/",array_reverse(explode("-",$data)));
		
		$pdf->Cell(60,20,utf8_decode($data),1,0,"L");
		$pdf->Cell(50,20,utf8_decode('R$ '.$row['valor']),1,0,"L");
		$pdf->Cell(100,20,utf8_decode($row['origem_destino']),1,0,"L");
		
		$pdf->Cell(40,20,utf8_decode($row['tipo_movimentacao']),1,0,"L");
		
		$pdf->Cell(120,20,utf8_decode($igreja['igreja']),1,0,"L");$pdf->Ln();
	$n++;
	}
	$pdf->Ln(10);
	//$n = mysql_num_rows($sql);
	$pdf->Cell(150, 20, utf8_decode("Total de Registros: ".$n));
	$pdf->Ln(40);
	
	$pdf->Output("entradas-saidas.pdf","I");
	
?>